<?php
if (!defined('IN_ELS'))
{
    die('Hacking attempt');
}
class control extends registerbase{
	
	/*
	'==========================================================================================
	'〖名 称〗:control构造
	'〖参 数〗:
	'==========================================================================================
	*/
	function control() {
		$this->registerbase();
		$act=empty($_REQUEST["a"]) ? "empty" : $_REQUEST["a"];
		if($act=="empty")				$this->register_index();//会员信息填写注册页面
		if($act=="sub1")				$this->sub1();//提交参数
		if($act=="regsave")				$this->regsave();
		if($act=="regsave2")			$this->regsave2();
		if($act=="reg2")				$this->reg2();
		if($act=="reg3")				$this->reg3();
		if($act=="check")				$this->check();
		if($act=="checks")				$this->checks();
		if($act=="checkss")				$this->checkss();
		if($act=="insertcode")			$this->insertcode();
		
		if($act=="requestcode")			$this->requestCode();
		if($act=="getphone")			$this->getphone();
	}


	function register_index()//会员信息填写注册页面
	{
		$_SESSION['user_name']=$user_info['nick_name'];
		$user_info = $this->getUserInfo($_SESSION['mid']);
		$_SESSION['user_name']=$user_info['nick_name'];
		$this->view->assign('user_info'  ,$user_info);
		$this->view->assign('user_name'  ,$_SESSION['user_name']);
		
		$agency_list = $this->get_agency();//获得机构列表
		$this->view->assign("agency_list",$agency_list);
		$footer_list = ($this->get_footer());
		$this->view->assign("footer_list",$footer_list);// 底部连接 footer
		
		$this->view->display("register");
	}
	function sub1()//会员提交参数信息
	{
		
		$dataArr = array(
			'true_name' => $_POST['name'],
			'hight' => $_POST['hi'],
			'weight' => $_POST['we'],
			'bust' => $_POST['x'],
			'waist' => $_POST['y'],
			'hip' => $_POST['t'],
			'city' => $_POST['city'],
			'tel' => $_POST['tel'],
			'QQ' => $_POST['qq'],
			'email' => $_POST['email'],
			'content' => $_POST['contents'],
			'renzheng_status'=>2
		);
		//print_r($dataArr);exit;
		$where = " id =".$_SESSION['mid'];
		$this->upUser('gnw_user',$dataArr,$where);
		echo "<script>alert('填写成功！1-2天审核！');location.href='?p=members';</script>";


	}




	
	//接收短信方 推回来的验证码
	function requestCode(){
		$userID = $_REQUEST['userID'];//账号
		$pwd = $_REQUEST['pwd'];//密码
		$content = $_REQUEST['content'];//验证码内容
		$mobile = $_REQUEST['mobile'];//手机号码
		
		if($userID == "aishang" && $pwd == "DC820A3B10BD22EF"){
			$end_time = date("Y-m-d",$this->getCurrTimeLine());
			$end_times =strtotime($end_time." 23:59:59");
			//接收验证码-用来匹对
			$codeArray = array();
			$codeArray['name'] = $content;
			$codeArray['code_time'] = $end_times;
			$retValues =$this->addCode($codeArray);
			//接受验证码 存为历史
			$dataArray = array();
			$dataArray['mobile'] = $mobile;
			$dataArray['content'] = $content;
			$dataArray['create_time'] = $this -> getCurrTimeLine();
			$retValues =$this->addcode_reg_history($dataArray);
			
		}
	}
	/**********
	//接收用户手机号并发送到短信平台
	function getphone(){
		$phone = $_REQUEST['phone'];
		$mobile_phones = $this->getUsernameInfo($phone);
		if(!empty($mobile_phones)){
			echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
			echo "<script charset='utf-8' type='text/javascript'>alert('手机号已存在');window.location.href='javascript:history.go(-1)';</script>";
		}elseif(empty($phone)){
			echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
			echo "<script charset='utf-8' type='text/javascript'>alert('手机号码不能为空。');window.location.href='javascript:history.go(-1)';</script>";
		}elseif (!eregi("^13[0-9]{9}$|15[0-9]{9}$|18[0-9]{9}$",$phone)) {
			echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
			echo "<script charset='utf-8' type='text/javascript'>alert('该手机号码格式不正确。');window.location.href='javascript:history.go(-1)';</script>";
		}else{
			$fp = fopen("http://119.8.187.219:8686/http/httpCode?userID=aishang&pwd=DC820A3B10BD22EF&mobile=".$phone,"r");
			$ret= fgetss($fp,255);
			if($ret == "100"){
				fclose($fp);
				$this->db->query("UPDATE members SET mobile_phone='$phone' WHERE mid='$_SESSION[mid]'");
				echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				echo "<script charset='utf-8' type='text/javascript'>alert('发送成功');window.location.href='javascript:history.go(-1)';</script>";
			//	echo $ret."<br>";
			}
			if($ret == "802"){
				fclose($fp);
				echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				echo "<script charset='utf-8' type='text/javascript'>alert('用户信息错');window.location.href='javascript:history.go(-1)';</script>";
			}
			if($ret == "803"){
				fclose($fp);
				echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				echo "<script charset='utf-8' type='text/javascript'>alert('手机号码格式不正确');window.location.href='javascript:history.go(-1)';</script>";
			
			}
			if($ret == "804"){
				fclose($fp);
				echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				echo "<script charset='utf-8' type='text/javascript'>alert('请求参数错误');window.location.href='javascript:history.go(-1)';</script>";
			
			}
			if($ret == "810"){
				fclose($fp);
				echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				echo "<script charset='utf-8' type='text/javascript'>alert('余额不足');window.location.href='javascript:history.go(-1)';</script>";
				
			}
			if($ret == "812"){
				fclose($fp);
				echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				echo "<script charset='utf-8' type='text/javascript'>alert('发送失败');window.location.href='javascript:history.go(-1)';</script>";
				
			}
			if($ret == "812"){
				fclose($fp);
				echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				echo "<script charset='utf-8' type='text/javascript'>alert('其他错误');window.location.href='javascript:history.go(-1)';</script>";
				
			}
		}
	}
	**************************************************/
	//注册入库基本信息
	function regsave(){
		// 取得表单数据
		$errData     = array();
		$divData     = array();
		
		$name   			= $this->replaceHtmlToAdditional(trim($_REQUEST["name"]));
		$nickname			= $this->replaceHtmlToAdditional(trim($_REQUEST["nickname"]));
		$password    		= $_REQUEST["reg_passwd"];
		$address			= $_REQUEST["address"];
		$mobile_phone   	= $_REQUEST["mobile_phone"];
		$email   			= $_REQUEST["email"];
		$sex   				= $_REQUEST["sex"];
		$user_type   		= $_REQUEST["user_type"];
		
		// 保留输入信息
		if(empty($password)){
			$errData[count($errData)] = "passWordTagDiv##* 密码长度必须在 6-16 个字符之间";
		}elseif (strlen($password)<6||strlen($password)>16){
			$errData[count($errData)] = "passWordTagDiv##* 密码长度必须在 6-16 个字符之间";
		}
		
	
		if(empty($mobile_phone)){
			$errData[count($errData)]="mobile_phoneTagDiv##* 请输入手机号码。";
		}elseif (!eregi("^13[0-9]{9}$|15[0-9]{9}$|18[0-9]{9}$",$mobile_phone)) {
			$errData[count($errData)] = "mobile_phoneTagDiv##* 该手机号码格式不正确";
		}
		
	
		if($address == ""){
			echo "000";exit;
		}
		if($nickname == ""){
			$errData[count($errData)]="nicknameTagDiv##* 请输入登陆账号。";
		}
		$nicknames = $this->getUsernamessInfo($nickname);
		if($nicknames){
			$errData[count($errData)]="nicknameTagDiv##* 此账号已存在。";
		}
		/*注销检测电子邮箱
		if($email == ""){
			$errData[count($errData)]="emailTagDiv##* 请输入电子邮箱。";
		}
		*/
		if(!empty($errData)){
			$divstr = "";
			foreach($errData as $k=>$a){
				if(!empty($divstr)){
					$divstr .= '!!'.$a;
				} else {
					$divstr .= $a;
				}
			}
			echo $divstr;
			exit;
		}
		//发送手机号给短信服务商
		
		$phone = $mobile_phone;
		$mobile_phones = $this->getUsernameInfo($phone);
		if(!empty($mobile_phones)){
			echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
			echo "<script charset='utf-8' type='text/javascript'>alert('手机号已存在');window.location.href='javascript:history.go(-1)';</script>";
		}elseif(empty($phone)){
			echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
			echo "<script charset='utf-8' type='text/javascript'>alert('手机号码不能为空。');window.location.href='javascript:history.go(-1)';</script>";
		}elseif (!eregi("^13[0-9]{9}$|15[0-9]{9}$|18[0-9]{9}$",$phone)) {
			echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
			echo "<script charset='utf-8' type='text/javascript'>alert('该手机号码格式不正确。');window.location.href='javascript:history.go(-1)';</script>";
		}else{
		
		$password = md5($password);
		// 写入数据库
//		$mid = $this -> CheckTableId("members");
		$dataArray						= array();
//		$dataArray['mid']				= $mid;
//		$dataArray['name']				= $name;
//		$dataArray['nickname']			= $nickname;
//		$dataArray['email']				= $email;
//		$dataArray['sex']				= $sex;
//		$dataArray['user_type']			= '2';
//		$dataArray['password']			= $password;
//		$dataArray['mobile_phone']		= $mobile_phone;
//		$dataArray['address']			= $address;
//		$dataArray['regip']				= $this->getonlineip();
		
	
		
		
	

			$fp = fopen("http://219.133.59.215:8686/http/httpCode?userID=aishang&pwd=DC820A3B10BD22EF&mobile=".$phone,"r");
			$ret= fgetss($fp,255);
			if($ret == "100"){
				fclose($fp);
				$this->db->query("UPDATE members SET mobile_phone='$phone' WHERE mid='$_SESSION[mid]'");
				//echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				//echo "<script charset='utf-8' type='text/javascript'>alert('发送成功');window.location.href='javascript:history.go(-1)';</script>";
				echo"发送成功";
				
				//	echo $ret."<br>";
			}
			if($ret == "802"){
				fclose($fp);
				//echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				//echo "<script charset='utf-8' type='text/javascript'>alert('用户信息错');window.location.href='javascript:history.go(-1)';</script>";
				//exit;
				echo"用户信息错";
				
			}
			if($ret == "803"){
				fclose($fp);
				//echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				//echo "<script charset='utf-8' type='text/javascript'>alert('手机号码格式不正确');window.location.href='javascript:history.go(-1)';</script>";
				//exit;
				echo"手机号码格式不正确";
				
			
			}
			if($ret == "804"){
				fclose($fp);
				//echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				//echo "<script charset='utf-8' type='text/javascript'>alert('请求参数错误');window.location.href='javascript:history.go(-1)';</script>";
				//exit;
				echo"请求参数错误";
				
			
			}
			if($ret == "810"){
				fclose($fp);
				//echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				//echo "<script charset='utf-8' type='text/javascript'>alert('余额不足');window.location.href='javascript:history.go(-1)';</script>";
				//exit;
				echo"余额不足";
				
				
			}
			if($ret == "812"){
				fclose($fp);
				//echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				//echo "<script charset='utf-8' type='text/javascript'>alert('发送失败');window.location.href='javascript:history.go(-1)';</script>";
				//exit;
				echo"发送失败";
			
				
			}
			if($ret == "812"){
				fclose($fp);
				//echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				//echo "<script charset='utf-8' type='text/javascript'>alert('其他错误');window.location.href='javascript:history.go(-1)';</script>";
				//exit;
				echo"其他错误";
			
			}
		}
		
		
		
		//发送手机号结束
		//$password = md5($password);
		
		// 写入数据库
//		$mid = $this -> CheckTableId("members");
		$dataArray						= array();
//		$dataArray['mid']				= $mid;
		$dataArray['name']				= $name;
		$dataArray['nickname']			= $nickname;
		$dataArray['email']				= $email;
		$dataArray['sex']				= $sex;
		$dataArray['user_type']			= '2';
		$dataArray['password']			= $password;
		$dataArray['mobile_phone']		= $mobile_phone;
		$dataArray['address']			= $address;
		$dataArray['regip']				= $this->getonlineip();
		$dataArray['create_time']		= $this -> getCurrTimeLine();
		$retValue = $this->addMember($dataArray);
		$mid = $this->db->insert_id();
		
		// 注册成功
		$_SESSION["mid"]				= $mid;
		$_SESSION["mobile_phone"]		= $mobile_phone;
	//	$num = 5;
	//	$start = 10000;
	//	$end = 99999;
	//	$connt = 0;
	//	$ary			= array();
	//	while($connt<$num){
	//		$a[]=rand($start,$end);//产生随机数
	//		$ary=array_unique($a);
	//		$connt++;
	//	}
	//	$codeArray				 = array();
	//	$codeArray['name']	 	 = $ary[0];
	//	$times = $this -> getCurrTimeLine();
	//	$code_time = $times + '60';
	//	$codeArray['code_time']  = $code_time;
	//	$retValues =$this->addCode($codeArray);
	//	$pa = md5('123.com');
	//	$this->sms_send('88000165',$pa,$mobile_phone,$ary[0]);
		exit;
	}
	
	function sms_send($user,$pass,$phone, $content) {
		$URL="http://3tong.cn:8082/ema_new/http/SendSms";
		$post_data['Account'] = $user;
		$post_data['Password'] =$pass;
		$post_data['Phone'] =$phone;
		$post_data['Content'] =$content;
		$post_data['SendTime'] =""; 
		$post_data['SubCode'] =""; 

		$referrer="";
		$URL_Info=parse_url($URL);
		if($referrer=="")
		$referrer=$_SERVER["SCRIPT_URI"];
		foreach($post_data as $key=>$value)
		$values[]="$key=".urlencode($value); 
		$data_string=implode("&",$values);
		if(!isset($URL_Info["port"]))
		$URL_Info["port"]=8082;
		$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
		$request.="Host: ".$URL_Info["host"]."\n";
		$request.="Referer: $referrer\n";
		$request.="Content-type: application/x-www-form-urlencoded\n";
		$request.="Content-length: ".strlen($data_string)."\n";
		$request.="Connection: close\n";
		$request.="\n";
		$request.=$data_string."\n";
		$fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
		fputs($fp, $request);
		while(!feof($fp)) {
		$result .= fgets($fp, 1024);
	}
	fclose($fp);
		return true;
	}
	
	function insertcode(){
		$mid	=	$_REQUEST["mid"];
		$userinfo = $this->getMidInfo($mid);
		$num = 5;
		$start = 10000;
		$end = 99999;
		$connt = 0;
		$ary			= array();
		while($connt<$num){
			$a[]=rand($start,$end);//产生随机数
			$ary=array_unique($a);
			$connt++;
		}
		$codeArray				 = array();
		$codeArray['name']	 	 = $ary[0];
		$times = $this -> getCurrTimeLine();
		$code_time = $times + '60';
		$codeArray['code_time']  = $code_time;
		$retValues =$this->addCode($codeArray);
		$pa = md5('123.com');
	//	$this->sms_send('88000165',$pa,$userinfo['mobile_phone'],$ary[0]);
		exit;
	}
//	function reg2(){
//		$userinfo = $this->getMidInfo($_SESSION['mid']);
//		
//		$this->view->assign('userinfo',$userinfo);
//		$this->view->display("register_2");
//	}
	function reg2(){
	
		$userinfo = $this->getMidInfo($_SESSION['mid']);
		
		$this->view->assign('userinfo',$userinfo);
		$this->view->display("register_2s");
	}
	//注册入库基本信息
	function regsave2(){
		$Code = $_REQUEST['codes'];
		
		if($Code == "" ){
			$this->view->assign('Code_err'  ,"*验证码不能为空");
			$this->view->assign('Code'  ,$Code);
		//	$this->view->display("register_2");
			$this->view->display("register_2s");
			exit;
		}
		$codeinfo = $this->getCodeInfo($Code);
		if($codeinfo == ""){
			$this->view->assign('Code_err'  ,"*验证码不存在");
			$this->view->assign('Code'  ,$Code);
			//$this->view->display("register_2");
			$this->view->display("register_2s");
			exit;
		}
		
		$times = $this -> getCurrTimeLine();
		if($codeinfo['type'] == "1"){
			$this->view->assign('Code_err'  ,"*验证码已过期");
			$this->view->assign('Code'  ,$Code);
			//$this->view->display("register_2");
			$this->view->display("register_2s");
			exit;
		}else{
			$regip		= $this->getonlineip();
			$regipInfo = $this->getregipInfo($regip);
			$code = $this->getCodeInfo($Code);
			$this->db->query("DELETE FROM code WHERE codeid='$code[codeid]'");
			$this->db->query("UPDATE members SET type = 1 WHERE mid='$_SESSION[mid]'");
			$this->db->query("UPDATE regip SET num=num-1 WHERE id='$regipInfo[id]'");
			$_SESSION["type"]		= 1;
			$this->pageRedirect("?p=register&a=reg3");
		}
	}
	function reg3(){
		$this->view->assign('linklist',$linklist);
		$this->view->display("register_3");
		echo "<script charset='utf-8' type='text/javascript'>setTimeout('window.location.href=\'index.php?p=user\'',5000);</script>";
	}
	function check(){
		$validateCode = $_REQUEST['validateCode'];
		$codeinfo = $this->getCodeInfo($validateCode);
		if($codeinfo != ""){
			if($codeinfo['type']=='1'){
				//验证码已过期
				echo "2";
				exit;
			}else{
				//验证码可以使用
				echo "3";
				exit;
			}
		}else{
			//验证码不存在
			echo "1";
			exit;
		}
	}
	function checks(){
		$mobile_phone = $_REQUEST['mobile_phone'];
		$userinfo = $this->getUsernameInfo($mobile_phone);
	
		if($userinfo){
			echo "1";
			exit;
		}else{
			echo "2";
			exit;
		}
		
	}
	function checkss(){
		$nickname = $_REQUEST['nickname'];
		$userinfo = $this->getUsernamessInfo($nickname);
	
		if($userinfo){
			echo "1";
			exit;
		}else{
			echo "2";
			exit;
		}
		
	}
}
?>